package acm.pta15;

import java.util.Scanner;
import java.util.Stack;

//单调栈+栈
public class 插松枝 {
    public static void print(Stack<Integer> stack) {
        StringBuilder sb = new StringBuilder();
        stack.forEach(e -> sb.append(e).append(" "));
        stack.clear();
        sb.deleteCharAt(sb.length() - 1);//删除最后一个空格
        System.out.println(sb);
    }

    static Stack<Integer> res = new Stack<>();   //存放结果的栈
    static Stack<Integer> box = new Stack<>(); //存放针的栈
    static int n;
    static int boxSize;

    public static void add(int num) {
        byBox();
        if (!byStream(num)) {
            pushBox(num);
        }
    }

    public static boolean byStream(int n) {
        if (res.isEmpty()) {
            res.push(n);
            return true;
        }
        if (res.peek() < n) return false;
        res.push(n);
        return true;
    }

    public static void byBox() {
        if (res.isEmpty()&&!box.isEmpty()) {
            res.push(box.pop());    //这里预先添加一个是为了防止下面爆空指针
        }
        while (!box.isEmpty() && box.peek() <= res.peek() && res.size() < n) {
            res.push(box.pop());
        }
        if (res.size() >= n) {
            print(res);
            byBox();
        }
    }

    public static void pushBox(int n) {
        if (box.size() >= boxSize) {
            print(res);
            byBox();
        }
        box.push(n);
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count = sc.nextInt();
        boxSize =sc.nextInt();
        n=sc.nextInt();
        for (int i = 0; i < count; i++) {
            add(sc.nextInt());
        }
        while (!box.isEmpty()) {
            byBox();
            print(res);
        }
        if (!res.isEmpty()) {
            print(res);
        }
    }
}
